home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / pc / windows / qtw_201 / setup / samples / vbrowser / vbrowser.bas < prev    next >
Encoding:
BASIC Source File  |  1994-12-19  |  8.4 KB  |  298 lines

  1. Option Explicit
  2. Option Base 1
  3.  
  4. ' Type Declarations
  5.  
  6. Type RECT
  7.     Left As Integer
  8.     Top As Integer
  9.     right As Integer
  10.     bottom As Integer
  11. End Type
  12.  
  13. Type MovieEntry
  14.     MovieName As String
  15.     MovieDesc As String
  16.     PicHandle As Integer
  17. End Type
  18.  
  19. ' Global Constants
  20.  
  21. Global Const DEFAULT_LIST = "vbrowser.lst"
  22. Global Const NUMTHUMBNAILS = 4
  23.  
  24. ' Global Data
  25.  
  26. Global FirstOffset As Integer
  27. Global IgnoreClick As Integer
  28. Global NumberMovies As Integer
  29. Global MovieList() As MovieEntry
  30.  
  31. ' Function Declarations in external DLL'S
  32.  
  33. Declare Sub InvertRect Lib "User" (ByVal hDC As Integer, lpRect As RECT)
  34. Declare Sub VBDisposePicture Lib "QTMovie.VBX" (ByVal phPicture As Integer)
  35. Declare Function VBDrawPicture Lib "QTMovie.VBX" (ByVal hDC As Integer, ByVal phThePict As Integer, lprcFrame As RECT, ByVal pprpProgressProc As Long) As Long
  36. Declare Function VBGetMoviePosterPict Lib "QTMovie.VBX" (ByVal mMovie As Long) As Integer
  37.  
  38. Sub DrawPanel (fra As Control)
  39. '   Draw two 3-D rectangles around the frame
  40.  
  41.     Const DARK_GRAY = &H808080
  42.     Const WHITE = &HFFFFFF
  43.  
  44.     Dim rc As RECT
  45.     Dim xFactor As Integer
  46.     Dim yFactor As Integer
  47.  
  48.     xFactor = Screen.TwipsPerPixelX
  49.     yFactor = Screen.TwipsPerPixelY
  50.  
  51. '   Draw inner frame; left and top lines are dark gray, right and bottom
  52. '   are white
  53.  
  54.     rc.Left = fra.Left - 1 * xFactor
  55.     rc.Top = fra.Top - 1 * yFactor
  56.     rc.right = fra.Left + fra.Width + 1 * xFactor
  57.     rc.bottom = fra.Top + fra.Height + 1 * yFactor
  58.  
  59.     VBrowser.Line (rc.Left, rc.Top)-(rc.right - 1, rc.Top), DARK_GRAY
  60.     VBrowser.Line (rc.Left, rc.Top)-(rc.Left, rc.bottom - 1), DARK_GRAY
  61.     VBrowser.Line (rc.right, rc.Top)-(rc.right, rc.bottom), WHITE
  62.     VBrowser.Line (rc.Left, rc.bottom)-(rc.right, rc.bottom), WHITE
  63.  
  64. '   Draw outer frame; left and top lines are white, right and bottom are
  65. '   dark gray
  66.  
  67.     rc.Left = fra.Left - 4 * xFactor
  68.     rc.Top = fra.Top - 4 * yFactor
  69.     rc.right = fra.Left + fra.Width + 4 * xFactor
  70.     rc.bottom = fra.Top + fra.Height + 4 * yFactor
  71.  
  72.     VBrowser.Line (rc.Left, rc.Top)-(rc.right, rc.Top), WHITE
  73.     VBrowser.Line (rc.Left, rc.Top)-(rc.Left, rc.bottom), WHITE
  74.     VBrowser.Line (rc.right, rc.Top + 1)-(rc.right, rc.bottom), DARK_GRAY
  75.     VBrowser.Line (rc.Left + 1, rc.bottom)-(rc.right, rc.bottom), DARK_GRAY
  76. End Sub
  77.  
  78. Function GetThumbNails () As Integer
  79. '   Read the browser list file; save the movie names and poster picture
  80. '   handles
  81.  
  82.     Dim MovieDesc As String
  83.     Dim MovieListFile As Integer
  84.     Dim MovieListName As String
  85.     Dim MovieLine As String
  86.     Dim MovieName As String
  87.     Dim posDesc As Integer
  88.  
  89. '   Establish an error handler
  90.  
  91.     On Error GoTo HandleThumbError
  92.  
  93. '   Get a file handle and establish the browser list file name; if none is
  94. '   given on the command line, use the default file name
  95.  
  96.     MovieListFile = FreeFile
  97.  
  98.     If Len(Command$) = 0 Then
  99.     MovieListName = DEFAULT_LIST
  100.     Else
  101.     MovieListName = Command$
  102.     End If
  103.  
  104. '   Open the browser list file; this file contains the list of movie file
  105. '   names to use; each line contains a fully qualified movie file name and
  106. '   an optional description
  107.  
  108.     Open MovieListName For Input As MovieListFile
  109.  
  110. '   Read the browser list file and store the movie name and associated
  111. '   poster picture handle into the MovieList array
  112.  
  113.     Do
  114.     Line Input #MovieListFile, MovieLine
  115.     
  116.     posDesc = InStr(MovieLine, " ")
  117.     If posDesc > 0 Then
  118.         MovieName = LCase$(Left$(MovieLine, posDesc - 1))
  119.         
  120.         Do
  121.         posDesc = posDesc + 1
  122.         Loop While posDesc <= Len(MovieLine) And Mid$(MovieLine, posDesc, 1) = " "
  123.         
  124.         MovieDesc = Mid$(MovieLine, posDesc)
  125.     Else
  126.         MovieName = LCase$(MovieLine)
  127.         MovieDesc = MovieName
  128.     End If
  129.  
  130.     NumberMovies = NumberMovies + 1
  131.     ReDim Preserve MovieList(NumberMovies) As MovieEntry
  132.  
  133.     MovieList(NumberMovies).MovieName = MovieName
  134.     MovieList(NumberMovies).MovieDesc = MovieDesc
  135.  
  136.     VBrowser!QTMovie.MovieName = MovieName
  137.     MovieList(NumberMovies).PicHandle = VBGetMoviePosterPict(VBrowser!QTMovie.Movie)
  138.     Loop While Not EOF(MovieListFile)
  139.  
  140.     Close MovieListFile
  141.  
  142. '   Display the movie poster frames as thumbnail bitmaps
  143.  
  144.     ShowThumbNails
  145.  
  146. '   All done
  147.  
  148.     GetThumbNails = True
  149.     Exit Function
  150.  
  151. HandleThumbError:
  152. '   Something went wrong; format an error message, set the error return and
  153. '   exit
  154.  
  155.     Title!cmdOK.Visible = True
  156.     Title!lblMessage.Caption = "Error: " & Error(Err)
  157.     DoEvents
  158.  
  159.     GetThumbNails = False
  160.     Exit Function
  161. End Function
  162.  
  163. Sub InvertPicture (pic As Control)
  164. '   Use the Windows InvertRect function to invert the pixels in a thumbnail
  165.  
  166.     Dim rcPic As RECT
  167.  
  168.     rcPic.Left = 0
  169.     rcPic.Top = 0
  170.     rcPic.right = pic.ScaleWidth * Screen.TwipsPerPixelX
  171.     rcPic.bottom = pic.ScaleHeight * Screen.TwipsPerPixelY
  172.  
  173.     InvertRect pic.hDC, rcPic
  174. End Sub
  175.  
  176. Sub Main ()
  177. '   This is the main routine; first, show the title form and load the
  178. '   VBrowser form (don't make the VBrowser form visible yet)
  179.  
  180.     Title.Show
  181.     DoEvents
  182.     Load VBrowser
  183.  
  184. '   Set some global data; we've got no movies so far and the first thumbnail's
  185. '   offset is zero
  186.  
  187.     FirstOffset = 0
  188.     NumberMovies = 0
  189.  
  190. '   Set the movie's poster width and height to that of the thumbnail client
  191.  
  192.     VBrowser!QTMovie.PosterWidth = VBrowser!picThumbNail(1).ScaleWidth
  193.     VBrowser!QTMovie.PosterHeight = VBrowser!picThumbNail(1).ScaleHeight
  194.  
  195. '   Read the browser list file and display the thumbnail bitmaps; if all
  196. '   went OK, unload the Title form and show the first movie
  197.  
  198.     If GetThumbNails() Then
  199.     Unload Title
  200.     ShowMovie 1
  201.     End If
  202. End Sub
  203.  
  204. Function max (iFirst As Integer, iSecond As Integer) As Integer
  205. '   Determine the maximum integer
  206.  
  207.     If iFirst > iSecond Then
  208.     max = iFirst
  209.     Else
  210.     max = iSecond
  211.     End If
  212. End Function
  213.  
  214. Function min (iFirst As Integer, iSecond As Integer) As Integer
  215. '   Determine the minimum integer
  216.  
  217.     If iFirst < iSecond Then
  218.     min = iFirst
  219.     Else
  220.     min = iSecond
  221.     End If
  222. End Function
  223.  
  224. Sub ShowMovie (MovieIndex As Integer)
  225. '   Position the VBrowser controls to be consistent with the movie size and
  226. '   resize the VBrowser form
  227.  
  228. '   These constants aid in the spatial layout of the individual controls
  229.  
  230.     Const OFFSET_THUMBNAIL = 540
  231.     Const OFFSET_FILENAME = 300
  232.     Const OFFSET_FORMHEIGHT = 720
  233.  
  234. '   Set the movie name from the MovieList; set the form's caption to the
  235. '   movie description
  236.  
  237.     VBrowser!QTMovie.MovieName = MovieList(MovieIndex).MovieName
  238.     VBrowser.Caption = MovieList(MovieIndex).MovieDesc
  239.  
  240. '   Size the frame to fit tightly around the movie; center the frame
  241.  
  242.     VBrowser!fraMovie.Width = VBrowser!QTMovie.Width
  243.     VBrowser!fraMovie.Height = VBrowser!QTMovie.Height
  244.     VBrowser!fraMovie.Left = (VBrowser.ScaleWidth - VBrowser!fraMovie.Width) / 2
  245.  
  246. '   Reposition the thumbnail frame
  247.  
  248.     VBrowser!fraThumbNail.Top = VBrowser!fraMovie.Top + VBrowser!fraMovie.Height + OFFSET_THUMBNAIL
  249.  
  250. '   Reposition the left and right thumbnail scroll buttons
  251.  
  252.     VBrowser!imgButtonLeft.Top = VBrowser!fraThumbNail.Top + (VBrowser!fraThumbNail.Height - VBrowser!imgButtonLeft.Height) / 2
  253.     VBrowser!imgButtonRight.Top = VBrowser!imgButtonLeft.Top
  254.  
  255. '   Reposition the file name label control
  256.  
  257.     VBrowser!lblFileName.Top = VBrowser!fraThumbNail.Top - OFFSET_FILENAME
  258.  
  259. '   Resize the VBrowser form and center it on the screen
  260.  
  261.     VBrowser.Height = VBrowser!fraThumbNail.Top + VBrowser!fraThumbNail.Height + OFFSET_FORMHEIGHT
  262.  
  263.     VBrowser.Left = (Screen.Width - VBrowser.Width) / 2
  264.     VBrowser.Top = (Screen.Height - VBrowser.Height) / 2
  265.     VBrowser.Refresh
  266.  
  267. '   Let the audience see what we have
  268.  
  269.     VBrowser.Show
  270. End Sub
  271.  
  272. Sub ShowThumbNails ()
  273. '   Display the thumbnail bitmaps
  274.  
  275.     Dim i As Integer
  276.     Dim VisibleNew As Integer
  277.  
  278. '   Force each thumbnail picture to be repainted
  279.  
  280.     For i = 1 To NUMTHUMBNAILS
  281.     VBrowser!picThumbNail(i).Refresh
  282.     DoEvents
  283.     Next i
  284.  
  285. '   Make the thumbnail scroll buttons visible or invisible as needed; only
  286. '   change the visibility property if it has changed
  287.  
  288.     VisibleNew = (FirstOffset >= 1)
  289.     If VisibleNew <> VBrowser!imgButtonLeft.Visible Then
  290.     VBrowser!imgButtonLeft.Visible = VisibleNew
  291.     End If
  292.  
  293.     VisibleNew = ((FirstOffset + NUMTHUMBNAILS) <= NumberMovies)
  294.     If VisibleNew <> VBrowser!imgButtonRight.Visible Then
  295.     VBrowser!imgButtonRight.Visible = VisibleNew
  296.     End If
  297. End Sub
  298.